package com.wwj.core.server.service.impl;

import com.wwj.core.server.entity.ControlServerConnect;
import com.wwj.core.server.entity.mapper.ControlServerConnectMapper;
import com.wwj.core.server.service.IControlServerConnectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ControlServerConnectServiceImpl implements IControlServerConnectService {

    @Resource
    private ControlServerConnectMapper controlServerConnectMapper;

    @Override
    public ControlServerConnect findConnect(Integer id, String serverName) throws Exception {
        return controlServerConnectMapper.selectByControlServerIdAndConnectServerName(id,serverName);
    }

    @Override
    public List<ControlServerConnect> findConnects(Integer id) throws Exception {
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("controlServerId",id);
        return controlServerConnectMapper.selectByParam(param);
    }

    @Override
    public int createNewConnect(ControlServerConnect connect) throws Exception {
        connect.setCreateTime(Calendar.getInstance().getTime());
        return controlServerConnectMapper.save(connect);
    }

    @Override
    public int updateConnect(ControlServerConnect connect) throws Exception {
        connect.setUpdateTime(Calendar.getInstance().getTime());
        return controlServerConnectMapper.update(connect);
    }
}
